include '%fasminc%\win64wxp.inc'
.dll DllEntryPoint

.const
  dllmsg du "FROM: ERRORMSG.DLL",0

.code
proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
     mov     rax, TRUE
     ret
endp

proc ShowErrorMessage hWnd, dwError
     local lpBuffer:QWORD

	 mov [hwnd],rcx
	 mov [dwError],rdx
     lea     rax, [lpBuffer]
     invoke  FormatMessage, FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_SYSTEM,\
	     0, [dwError], LANG_NEUTRAL, rax, 0, 0

     invoke  MessageBox, [hWnd], [lpBuffer], dllmsg, MB_ICONERROR or MB_OK

     invoke  LocalFree, [lpBuffer]
     return
endp

; VOID ShowLastError(HWND hWnd);

proc ShowLastError hWnd
     mov [hwnd],rcx
     invoke  GetLastError
     stdcall ShowErrorMessage, [hWnd], rax
     return
endp

.idata
  library_sys

.edata
  export 'ERRORMSG.DLL',\
	 ShowErrorMessage,'ShowErrorMessage',\
	 ShowLastError,'ShowLastError'

.reloc
